<?php
/**
 * 手机号归属地查询
 * @author xiaogg<xiaogg@sina.cn>
 * @qq 756663992
 */
error_reporting("E_ALL");ini_set("display_errors", 1);header("content-Type: application/json; charset=utf-8");
include('include/function.php');
include('include/JsonDB.class.php');
$mobile=!empty($_REQUEST['mobile'])?trim($_REQUEST['mobile']):'';
if(empty($mobile)){
    $return=array('status'=>0,'info'=>'请填写手机号');ajaxReturn($return);
}
if(!is_mobile($mobile)){
    $return=array('status'=>0,'info'=>'请填写正确手机号');ajaxReturn($return);
}
$db='mobile'.substr($mobile,0,3);
$dbfile='./data/'.$db.'.json';
if(!file_exists($dbfile)){$return=array('status'=>0,'info'=>'暂无该号段信息');ajaxReturn($return);}
$mobpre=substr($mobile,0,7);
$cache=filecache($mobpre);if($cache){$cache['mobile']=$mobile;ajaxReturn($cache);}
$jsondb = new JsonDB($db);$param=array();
$param['phone']=$mobpre;
$info=$jsondb->find($param);
if($info){
    if($info['areaid']){        
        $jsondb->open('youbian');
        $param=array();
        $param['id']=$info['areaid'];
        $area=$jsondb->find($param);
        $detail=$info+$area;
    } else $detail=$info;unset($detail['id'],$detail['areaid'],$detail['phone']);
    $detail['status']=1;filecache($mobpre,$detail);$detail['mobile']=$mobile;
    ajaxReturn($detail);
}else{
    $return=array('status'=>0,'info'=>'没有查询到信息');ajaxReturn($return);
}
?>